package org.admin.entity.domain;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@Data
@TableName("admin_roles")
public class Role {
    @Getter
    public enum UPLOAD{
        FALSE(0),
        TRUE(1);
        private final int value;
        UPLOAD(int value) {
            this.value = value;
        }
    }

    @TableId(type = IdType.AUTO)
    private Integer id;
    private String name;

    @Setter(AccessLevel.NONE)
    private Integer upload;

    @Setter(AccessLevel.NONE)
    @TableField(exist = false)
    private UPLOAD uploadWith;

    @TableField("created_at")
    private Date createdAt;

    @TableField("updated_at")
    private Date updateAt;

    @TableLogic
    @TableField("deleted_at")
    private Date deletedAt;
    public void setUpload(Integer value){
        upload = value;
        if(value != null) {
            for (UPLOAD item : UPLOAD.values()) {
                if (item.getValue() == value) {
                    uploadWith = item;
                    break;
                }
            }
        }else{
            uploadWith = null;
        }
    }
    public void setUploadWith(UPLOAD value){
        upload = value.getValue();
        uploadWith = value;
    }
}
